package gw.demo2.service;

import gw.demo2.entity.Product;
import gw.demo2.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {
    @Autowired
    private ProductMapper productMapper;

    public List<Product> getAllProducts() {
        return productMapper.selectAllProducts();
    }

    public Product getProductById(int productId) {
        return productMapper.selectProductById(productId);
    }

    public boolean addProduct(Product product) {
        return productMapper.insertProduct(product) > 0;
    }

    public boolean updateProduct(Product product) {
        return productMapper.updateProduct(product) > 0;
    }

    public boolean deleteProduct(int productId) {
        return productMapper.deleteProduct(productId) > 0;
    }
}